package com.kuang.service;

import com.kuang.bean.Order;
import com.kuang.bean.OrderExample;
import com.kuang.dao.OrderMapper;
import com.kuang.utils.GetTime;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
@Service
public class OrderServiceImpl implements OrderService {

    @Autowired
    private OrderMapper orderMapper;

    OrderExample orderExample = new OrderExample();
    OrderExample.Criteria criteria = orderExample.createCriteria();
    GetTime getTime = new GetTime();

    public void setOrderMapper(OrderMapper orderMapper) {
        this.orderMapper = orderMapper;
    }

    public int addOrder(Order order) {
        return orderMapper.insert(order);
    }

    public int deleteOrderById(int id) {
        return orderMapper.deleteByPrimaryKey(id);
    }

    public int updateOrder(Order order) {
        return orderMapper.updateByPrimaryKey(order);
    }

    public Order queryOrderById(int id) {
        return orderMapper.selectByPrimaryKey(id);
    }

    public List<Order> queryOrderByTime() {
        criteria.andCreateTimeBetween(getTime.getBefore(),getTime.getNow());
        return orderMapper.selectByExample(orderExample);
    }

    public List<Order> queryOrderByStatus(int status) {
        criteria.andOrderStatusEqualTo(status);
        return orderMapper.selectByExample(orderExample);
    }

    public List<Order> queryAllOrder() {
        return orderMapper.selectByExample(orderExample);
    }

}
